%% Check coverage of CIs & Compute empirical coverage probability

function empirical_cov = check_CI_over_nu(hat_vartheta, rep_val_se2, bar_tau, bar_V_tau, nu)
% INPUT: validation study estimates hat_vartheta, reported validation study se^2 rep_val_se2, 
% posterior moments bar_tau, bar_V_tau, EB estimate nu
% OUTPUT: empirical coverage probability empirical_cov

    N = size(hat_vartheta,1);

    % Compute the upper and lower bounds
    predict_se = sqrt(rep_val_se2 + nu + bar_V_tau);
    lower_bound = bar_tau - 1.282 * predict_se;
    upper_bound = bar_tau + 1.282 * predict_se;

    % Check whether the reported estimates lie in the predicted CIs
    hit = (hat_vartheta >= lower_bound) & (hat_vartheta <= upper_bound);

    % Compute empirical coverage prob
    empirical_cov = sum(hit)/N;
    
end